import os

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from dianzishangwu_testing.page_objects.base_page import BasePage
from dianzishangwu_testing.until.web_util import click_exprction


class CategoryCreatePage(BasePage):

    __CATEGORY_NAME = (By.XPATH, "//*[text()='类目名称']/..//input")
    __UPLOAD_PICE = (By.XPATH, "//*[text()='类目图片']/..//input")
    __BTN_CONFIRM = (By.XPATH, "//*[text()='确定']/..")
    __IMAGE_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "images", "1651901834.png")

    def create_category(self, category_name):
        self.do_send_keys(category_name, self.__CATEGORY_NAME)
        print(self.__IMAGE_PATH)
        self.do_upload_pice(f"{self.__IMAGE_PATH}", self.__UPLOAD_PICE)
        self.wait_web_driver(click_exprction(*self.__BTN_CONFIRM))
        # 创建完成后返回到商品列表页
        from dianzishangwu_testing.page_objects.category_list_page import CategoryListPage
        return CategoryListPage(self.driver)